﻿// GlueCheckDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "GlueCheckDlg.h"
#include "afxdialogex.h"


// CGlueCheckDlg 对话框

IMPLEMENT_DYNAMIC(CGlueCheckDlg, CDialogEx)

CGlueCheckDlg::CGlueCheckDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_GLUE_CHECK, pParent)
	, GlueID(_T(""))
	, GlueLifeLimit(0)
	, GlueLastTime(_T(""))
{

}

CGlueCheckDlg::~CGlueCheckDlg()
{
}

void CGlueCheckDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, GlueID);
	DDX_Text(pDX, IDC_EDIT2, GlueLifeLimit);
	DDX_Text(pDX, IDC_STATIC_TIME, GlueLastTime);
}


BEGIN_MESSAGE_MAP(CGlueCheckDlg, CDialogEx)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON1, &CGlueCheckDlg::OnBnClickedButton1)
END_MESSAGE_MAP()


// CGlueCheckDlg 消息处理程序


BOOL CGlueCheckDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	GlueID = gSystemMgr.GlueID;
	GlueLifeLimit = gSystemMgr.GlueLifeLimit;
	GlueLastTime.Format(L"%02d/%02d-%02d:%02d", gSystemMgr.GlueMonth, gSystemMgr.GlueDay, gSystemMgr.GlueHour, gSystemMgr.GlueMinute);

	UpdateData(FALSE);

	return TRUE; 
}


void CGlueCheckDlg::OnCancel()
{
	// TODO: 在此添加专用代码和/或调用基类

	CDialogEx::OnCancel();
}


void CGlueCheckDlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	CDialogEx::OnTimer(nIDEvent);
}


void CGlueCheckDlg::OnBnClickedButton1()
{
	if (IDYES == AfxMessageBox(L"确定 更新胶水信息 吗？", MB_YESNO | MB_ICONWARNING))
	{
		UpdateData(TRUE);

		gSystemMgr.GlueID = GlueID;
		gSystemMgr.GlueLifeLimit = GlueLifeLimit;

		SYSTEMTIME st;
		GetLocalTime(&st);
		gSystemMgr.GlueMonth = st.wMonth;
		gSystemMgr.GlueDay = st.wDay;
		gSystemMgr.GlueHour = st.wHour;
		gSystemMgr.GlueMinute = st.wMinute;

		CString cstr;

		cstr.Format(L"%d", gSystemMgr.GlueMonth); gSystemMgr.m_cGlueCheckConfigIni.SaveConfigIni(L"GlueCheck", L"GlueMonth", cstr);
		cstr.Format(L"%d", gSystemMgr.GlueDay); gSystemMgr.m_cGlueCheckConfigIni.SaveConfigIni(L"GlueCheck", L"GlueDay", cstr);
		cstr.Format(L"%d", gSystemMgr.GlueHour); gSystemMgr.m_cGlueCheckConfigIni.SaveConfigIni(L"GlueCheck", L"GlueHour", cstr);
		cstr.Format(L"%d", gSystemMgr.GlueMinute); gSystemMgr.m_cGlueCheckConfigIni.SaveConfigIni(L"GlueCheck", L"GlueMinute", cstr);

		cstr.Format(L"%.3f", gSystemMgr.GlueLifeLimit); gSystemMgr.m_cGlueCheckConfigIni.SaveConfigIni(L"GlueCheck", L"GlueLifeLimit", cstr);

		gSystemMgr.m_cGlueCheckConfigIni.SaveConfigIni(L"GlueCheck", L"GlueID", gSystemMgr.GlueID);

		gSystemMgr.SaveTestGlue();

		GlueLastTime.Format(L"%02d/%02d-%02d:%02d", gSystemMgr.GlueMonth, gSystemMgr.GlueDay, gSystemMgr.GlueHour, gSystemMgr.GlueMinute);

		UpdateData(FALSE);
	}
}

